package com.loveprogrammer.pojo;

import com.alibaba.fastjson2.JSON;
import com.baidu.bjf.remoting.protobuf.FieldType;
import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;
import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;

/**
 * @ClassName StringMessage
 * @Description string类型的请求的请求体
 * @Author admin
 * @Date 2024/1/31 10:35
 * @Version 1.0
 */
@ProtobufClass
public class CodeMessage {

    /***
     *         code 消息码，确定消息的类型
     *         statusC内容的长ode主要是返回内容是告诉客户端消息的状态，成功为1，其他不同的错误使用不同的错误码
     *         length是度，内容的长度是不可控制的，所以使用一个长度进行定义
     *         body是具体的内容
     */
    @Protobuf(fieldType = FieldType.INT32)
    private int code;

    @Protobuf(order =  1, fieldType = FieldType.INT32)
    private int statusCode;

    @Protobuf(order =  2, fieldType = FieldType.INT32)
    private int length;

    @Protobuf(order =  3)
    private String body;

    public CodeMessage() {
    }

    public static CodeMessage create(int code) {
        CodeMessage stringMessage = new CodeMessage();
        stringMessage.setCode(code);
        return stringMessage;
    }

    public static CodeMessage create(String origin) {
        CodeMessage stringMessage = JSON.parseObject(origin, CodeMessage.class);
        return stringMessage;
    }

    public static CodeMessage create(int length, int code, int statusCode, String content) {
        return new CodeMessage(length, code, statusCode, content);
    }

    private CodeMessage(int length, int code, int statusCode, String body) {
        this.length = length;
        this.code = code;
        this.statusCode = statusCode;
        this.body = body;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    @Override
    public String toString() {
        return "StringMessage{" + "code =" + code + ", statusCode=" + statusCode + ", length=" + length
                + ", body='" + body + '\'' + '}';
    }
}
